
const weexFunction = weex.requireModule("WeexFunction");

var urls = {'mine/DialogSignin':'mine/Signin'}
export default {

    /** 打开WEEX界面
     * 
     * @param {String} title 标题
     * @param {String} url 地址
     * @param {JSON or String} param 参数 
     * @param {JSON or String} option 导航栏配置
     */
    open(title, url, param, option){
        url = urls[url] ? urls[url] : url;
        param = this.getString(param);
        option = this.getString(option);
        weexFunction.open(title, url, param, option);
    },

    /** 打开WEEX弹窗
     * 
     * @param {String} url 地址
     * @param {JSON or String} param 参数 
     * @param {JSON or String} option 导航栏配置
     */
    openDialog(url, param, option){
        url = urls[url] ? urls[url] : url;
        param = this.getString(param);
        option = this.getString(option);
        weexFunction.openDialog(url, param, option);
    },

    /** 打开APP界面
     * 
     * @param {String} url 地址
     * @param {JSON or String} param 参数 
     */
    openNative(pageName, param){

        param = this.getString(param);
        weexFunction.openNative(pageName, param);
    },
    
    /** 刷新WEEX界面
     * 
     * @param {String} url 地址
     * @param {JSON or String} param 参数 
     * @param {JSON or String} option 导航栏配置
     */
    load(title, url, param, option){
        url = urls[url] ? urls[url] : url;
        param = this.getString(param);
        option = this.getString(option);
        weexFunction.loadUrl(title, url, param, option);
    },

    
    //界面后退
    back(num){
        num = num ? num : 1;
        weexFunction.back(num);
    },
    
    //关闭弹窗
    dismiss(){
        weexFunction.dismiss();
    },

    //获取参数
    getParam(key){
        return weex.config[key];
    },

    /********************* 其他私有方法*/
    //获取字符串
    getString(data) {
        data = data == undefined ? "{}" : data;
        data = typeof data == 'object' ? JSON.stringify(data) : data;
        return data;
    },
}
  